local skel = fk.CreateSkill{
  name = "tea__xiaobai",
}
local U = require "packages/utility/utility"
Fk:loadTranslationTable{
  ["tea__xiaobai"] = "晓白",
  [":tea__xiaobai"] = "每轮限一次，当有角色受到伤害后，你可以亮出牌堆底四张牌，若其中有牌与造成此伤害的牌牌名相同，你获得其中另外两张牌名不同的牌。"..
  "若此伤害：为属性伤害，你多亮出两张牌；为致命伤害，你多获得一张牌。",
  ["#tea__xiaobai-obtain"] = "选择 %arg 张牌获得",
}
---@type TrigSkelSpec<DamageTrigFunc>
local xiaobai = {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and player:usedSkillTimes(skel.name, Player.HistoryRound) and data.damage > 0 and data.card
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local num = 4
    local obtainNum = 2
    if data.damageType ~= fk.NormalDamage then
      num = num + 2
    end
    if player:getMark("xiaobai_damage_record") > 0 then
      obtainNum = obtainNum + 1
    end
    local cids = room:getNCards(num)
    room:moveCardTo(cids, Card.Processing, nil, fk.ReasonJustMove, skel.name, nil, true, player)
    if table.find(cids, function(id)
      return Fk:getCardById(id).trueName == data.card.trueName
    end) then
      local to_select = table.filter(cids, function(id)
        return Fk:getCardById(id).trueName ~= data.card.trueName
      end)
      if #to_select > 0 then
        if #to_select <= obtainNum then
          for _, id in ipairs(to_select) do
            table.removeOne(cids, id)
          end
          room:obtainCard(player, to_select, true, fk.ReasonJustMove, player, skel.name)
        else
          local cards, choice = room:askToChooseCardsAndChoice(player, {
            cards = to_select,
            choices = { "OK" },
            prompt = "#tea__xiaobai-obtain:::" .. tostring(obtainNum),
            cancel_choices = {},
            skill_name = skel.name,
            min_num = obtainNum,
            max_num = obtainNum
          })
          if choice == "OK" and #cards > 0 then
            for _, id in ipairs(cards) do
              table.removeOne(cids, id)
            end
            room:obtainCard(player, cards, true, fk.ReasonJustMove, player, skel.name)
          end
        end
      else
        room:delay(1500)
      end
    end
    room:moveCardTo(cids, Card.DiscardPile, nil, fk.ReasonJustMove, skel.name)
  end
}
---@type TrigSkelSpec<DamageTrigFunc>
local xiaobai_re = {
  priority = 0.0001,
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(skel.name, true)
  end,
  on_refresh = function (self, event, target, player, data)
    if data.damage >= target.hp then
      player.room:setPlayerMark(player, "xiaobai_damage_record", 1)
    else
      player.room:setPlayerMark(player, "xiaobai_damage_record", 0)
    end
  end
}
skel:addEffect(fk.Damaged, xiaobai)
skel:addEffect(fk.DamageInflicted, xiaobai_re)
return skel